//
//  AdviceViewController.m
//  Dear
//
//  Created by n22 on 15/7/17.
//  Copyright (c) 2015年 陈俊俊. All rights reserved.
//

#import "AdviceViewController.h"
#import "PlaceholderTextView.h"
@interface AdviceViewController ()
@property (weak, nonatomic) IBOutlet UITextField *contractTextField;
@property (weak, nonatomic) IBOutlet PlaceholderTextView *feedContentTextView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *feedTopHeight;

@end

@implementation AdviceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTitleViewWith:@"提交反馈意见"];
    self.view.backgroundColor = RGBA(246, 246, 246, 1);
    [self.feedContentTextView initObserver];
    self.feedContentTextView.layer.masksToBounds = YES;
    self.feedContentTextView.layer.cornerRadius = 5;
    self.feedContentTextView.font = [UIFont systemFontOfSize:14.0f];
    self.feedContentTextView.m_placeHolder = @"请输入反馈意见";
    self.feedContentTextView.m_placeholderColor  = [UIColor colorWithWhite:109/255.0f alpha:1];
}

- (IBAction)submitAdvice:(id)sender {
    NSString *contract = [CJJHelper trimmingWhitespace:self.contractTextField.text];
    NSString *feedContent = [CJJHelper trimmingWhitespace:self.feedContentTextView.text];
    if (contract.length == 0 || feedContent.length == 0) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"信息不完整" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        NSDictionary *dict = @{@"userId":[DearUser sharedInstance].userId,@"feedContent":feedContent,@"contract":contract};
        NSString *url = [ServerUrl stringByAppendingFormat:@"/%@",DearHttpFeedBack];
        [[HttpRequest sharedInstance] POST:url parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
            [DearLoadingView hideHUD];
            if (responseObject) {
                NSDictionary *dict = (NSDictionary *)responseObject;
                if ([dict[@"Result"] integerValue] == 0)
                {
                    //反馈成功
                    [DearLoadingView showTips:dict[@"Message"]];
                    //清空信息
                    self.contractTextField.text = @"";
                    self.feedContentTextView.text = @"";
                    self.feedContentTextView.m_placeHolder = @"请输入反馈意见";
                    self.feedContentTextView.m_placeholderColor  = [UIColor colorWithWhite:109/255.0f alpha:1];
                }else {
                    [DearLoadingView showTips:dict[@"Message"]];
                }
            }else{
                [DearLoadingView showTips:@"登录失败"];
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [DearLoadingView hideHUD];
            [DearLoadingView showTips:error];
        }];
 
    }
    
}

#pragma mark - 收键盘
- (void)keyboardHidden{
    [self.contractTextField resignFirstResponder];
    [self.feedContentTextView resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
